package com.xzc.one.business.service.web;

import com.xzc.one.business.mapper.dao.web.PermissionDao;
import com.xzc.one.business.pojo.entity.Permission;
import com.xzc.one.common.inout.exception.GlobalException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * author name: xiongzhicong
 * create time: 2020-08-10 17:40:11
 * description: 权限表
 */
@Service
public class PermissionService {

    @Autowired
    private PermissionDao permissionDao;

    public Integer insertPermission(Permission permission) {
        if (permission.getName() == null) {
            throw new GlobalException("name名称不能为空");
        }
        if (permission.getResource() == null) {
            throw new GlobalException("resource资源不能为空");
        }
        if (permission.getAccess() == null) {
            throw new GlobalException("access权限不能为空");
        }
        if (permission.getNote() == null) {
            throw new GlobalException("note备注不能为空");
        }
        if (permission.getCreateUserId() == null) {
            throw new GlobalException("createUserId创建人id不能为空");
        }
        if (permission.getUpdateUserId() == null) {
            throw new GlobalException("updateUserId修改人id不能为空");
        }
        if (permission.getCreateTime() == null) {
            throw new GlobalException("createTime创建时间不能为空");
        }
        if (permission.getUpdateTime() == null) {
            throw new GlobalException("updateTime修改时间不能为空");
        }
        System.out.println(permissionDao.countByWhere(new Permission() {{
            setAccess("anon");
        }}));
        return permissionDao.insert(permission);
    }

    public Permission test() {
        Permission permission = new Permission();
        permission.setAccess("anon");
        System.out.println(permissionDao.countByWhere(permission));
        System.out.println(permissionDao.queryById(83L).toString());
        System.out.println(permissionDao.queryOne(permission).toString());
        return permissionDao.queryById(83L);
    }
}
